package com.cjjd.c.feature.subscribe.select_hotel;

import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.cjjd.c.R;
import com.cjjd.c.ShareKeys;
import com.cjjd.c.base.BaseSwipeRefreshFragment;
import com.cjjd.c.base.MyBaseAdapter;
import com.cjjd.c.bean.HttpResult;
import com.cjjd.c.bean.subscribe.HotelQuestionShowModel;
import com.cjjd.c.bean.subscribe.QuestionModel;
import com.cjjd.c.http.JsonUtils;
import com.cjjd.c.utils.SharePrefUtil;

import java.util.HashMap;

import retrofit2.Call;
import retrofit2.Response;

/**
 * ----------------------------------
 * Created by xyd on 2017/12/1.
 * <p/>
 * 描  述：问大家
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class AskFragment extends BaseSwipeRefreshFragment {


    private TextView headView;
    private TextView footView;

    @Override
    public Object getTitleString() {
        return "问大家";
    }

    @Override
    public void responseSuccess(Call<HttpResult> call, Response<HttpResult> response) {


        QuestionModel<HotelQuestionShowModel> result = (QuestionModel<HotelQuestionShowModel>) response.body().getData();
        headView.setText("共有" + result.totalCount + "条回答");
        setDataList(result.dataList);
    }

    @Override
    public MyBaseAdapter getAdapter() {
        return new AskAdapter(mContext);
    }


    @Override
    protected void initView() {
        super.initView();
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_header_ask, emptyview, false);
        headView = (TextView) view.findViewById(R.id.tv_header);

        footView = new TextView(mContext);
        footView.setText("没有更多记录啦~");
        footView.setGravity(Gravity.CENTER);
        footView.setTextColor(getResources().getColor(R.color.textColorNomal));
        footView.setPadding(30, 30, 30, 30);
        listBase.addHeaderView(view);
        listBase.addFooterView(footView);
    }

    @Override
    public Call<HttpResult> getCall() {

        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));
        // TODO: 2017/12/19 这里要替换
        h1.put("hotelUuid", "0424252f017e49289b68c9987d6b6e0d");
        h1.put("pageNow", PAGE + "");
        h1.put("pageShow", PAGE_SIZE + "");

        return service.getHotelQuestionList(JsonUtils.convertParam("getHotelQuestionList", h1));
    }
}
